import { defineConfig, devices } from "@playwright/test";
import dotenv from "dotenv";
import path from "path";

// 加载环境变量
const commandType = process.env.COMMAND_TYPE || "test";
dotenv.config({ path: ".env" });
dotenv.config({ path: `.env.${commandType}`, override: true });

export default defineConfig({
  testDir: `./automation/${commandType}`,
  fullyParallel: true,
  forbidOnly: !!process.env.CI,
  retries: process.env.CI ? 2 : 0,
  workers: process.env.CI ? 1 : undefined,
  reporter: [["html", { open: "never" }]],

  use: {
    baseURL: process.env.TARGET_URL,
    trace: "on-first-retry",
    video: "on",
  },

  projects: [
    {
      name: "chrome",
      use: {
        browserName: "chromium",
        channel: "chrome",
        viewport: { width: 1920, height: 1080 },
        launchOptions: {
          // executablePath: process.env.CHROME_PATH,
          headless: false,
          args: [
            "--no-sandbox",
            "--disable-background-timer-throttling",
            "--disable-backgrounding-occluded-windows",
            "--disable-renderer-backgrounding",
            "--start-maximized",
            `--disable-extensions-except=${path.join(
              __dirname,
              "extensions/chrome-mv3-prod"
            )}`,
            `--load-extension=${path.join(
              __dirname,
              "extensions/chrome-mv3-prod"
            )}`,
          ],
        },
      },
    },
  ],
});
